<?php

namespace app\admin\controller;

use think\Controller;
use think\facade\Env;

class UploadController extends Controller
{
    public function index()
    {
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('file');

        // 移动到框架应用根目录/public/uploads/ 目录下
        if ($file) {
            $info = $file->move(Env::get('ROOT_PATH') . 'public' . '/' . 'uploads/image/');
            if ($info) {
                return zbcjson([
                    'src' => '/uploads/image/' . $info->getSaveName()
                ]);
            } else {
                return zbcjson(false, $info->getError());
            }
        }
    }
}
